package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domin.dto.LearningPlanDTO;
import com.tianji.learning.domin.vo.LearningLessonVO;
import com.tianji.learning.domin.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-08-26
 */
@Api(tags = "我的课表相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService lessonService;

    @ApiOperation("查询我的课表，排序字段 latest_learn_time:学习时间排序，create_time:购买时间排序")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query) {
        return lessonService.queryMyLessons(query);
    }

    @ApiOperation("查询最近学习的课程")
    @GetMapping("/now")
    public LearningLessonVO queryMyCurrentLesson() {
        return lessonService.queryMyCurrentLesson();
    }

    @ApiOperation("查询学习状态")
    @GetMapping("/{courseId}")
    public LearningLessonVO queryMyLessonStatus(@PathVariable("courseId") Long courseId) {

        return lessonService.queryMyLessonStatus(courseId);
    }

    @ApiOperation("检查当前用户的课表中是否有该课程，课程状态是否有效")
    @GetMapping("/{courseId}/valid")
    public Long checkCourseAvailability(@PathVariable("courseId") Long courseId) {
        return lessonService.checkCourseAvailability(courseId);
    }

    @ApiOperation("统计课程的学习人数")
    @GetMapping("/{courseId}/count")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId) {
        return lessonService.countLearningLessonByCourse(courseId);
    }

    @ApiOperation("创建学习计划")
    @PostMapping("plans")
    public void createLessonPlans(@RequestBody LearningPlanDTO dto) {
        lessonService.createLessonPlans(dto);
    }

    @ApiOperation("查询学习计划进度")
    @GetMapping("plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery) {
       return lessonService.queryMyPlans(pageQuery);
    }
}
